<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE FlexibleContexts #-}</span><span class="hs-cpp">
#if !(MIN_VERSION_base(4,11,0))
</span><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- | This module was written based on</span><span>
</span><span id="line-8"></span><span class="hs-comment">--   &lt;http://hackage.haskell.org/package/reinterpret-cast-0.1.0/docs/src/Data-ReinterpretCast-Internal-ImplArray.html&gt;.</span><span>
</span><span id="line-9"></span><span class="hs-comment">--</span><span>
</span><span id="line-10"></span><span class="hs-comment">--   Implements casting via a 1-element STUArray, as described in</span><span>
</span><span id="line-11"></span><span class="hs-comment">--   &lt;http://stackoverflow.com/a/7002812/263061&gt;.</span><span>
</span><span id="line-12"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.Binary.FloatCast</span><span>
</span><span id="line-13"></span><span>  </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Data.Binary.FloatCast.html#floatToWord"><span class="hs-identifier">floatToWord</span></a></span><span>  </span><span class="annot"><span class="hs-comment">-- | Reinterpret-casts a `Float` to a `Word32`.</span></span><span>
</span><span id="line-14"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Binary.FloatCast.html#wordToFloat"><span class="hs-identifier">wordToFloat</span></a></span><span>  </span><span class="annot"><span class="hs-comment">-- | Reinterpret-casts a `Word32` to a `Float`.</span></span><span>
</span><span id="line-15"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Binary.FloatCast.html#doubleToWord"><span class="hs-identifier">doubleToWord</span></a></span><span> </span><span class="annot"><span class="hs-comment">-- | Reinterpret-casts a `Double` to a `Word64`.</span></span><span>
</span><span id="line-16"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Binary.FloatCast.html#wordToDouble"><span class="hs-identifier">wordToDouble</span></a></span><span> </span><span class="annot"><span class="hs-comment">-- | Reinterpret-casts a `Word64` to a `Double`.</span></span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#if MIN_VERSION_base(4,11,0)
</span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Word.html#"><span class="hs-identifier">Data.Word</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Word.html#Word32"><span class="hs-identifier">Word32</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word64"><span class="hs-identifier">Word64</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Float.html#"><span class="hs-identifier">GHC.Float</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Float.html#castWord32ToFloat"><span class="hs-identifier">castWord32ToFloat</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Float.html#castFloatToWord32"><span class="hs-identifier">castFloatToWord32</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Float.html#castWord64ToDouble"><span class="hs-identifier">castWord64ToDouble</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Float.html#castDoubleToWord64"><span class="hs-identifier">castDoubleToWord64</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-24"></span><span>
</span><span id="line-25"></span><span class="annot"><a href="Data.Binary.FloatCast.html#floatToWord"><span class="hs-identifier hs-type">floatToWord</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span>
</span><span id="line-26"></span><span id="floatToWord"><span class="annot"><span class="annottext">floatToWord :: Float -&gt; Word32
</span><a href="Data.Binary.FloatCast.html#floatToWord"><span class="hs-identifier hs-var hs-var">floatToWord</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Float -&gt; Word32
</span><a href="../../base/src/GHC.Float.html#castFloatToWord32"><span class="hs-identifier hs-var">castFloatToWord32</span></a></span><span>
</span><span id="line-27"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.Binary.FloatCast.html#floatToWord"><span class="hs-pragma hs-type">floatToWord</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span class="annot"><a href="Data.Binary.FloatCast.html#wordToFloat"><span class="hs-identifier hs-type">wordToFloat</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Float</span></span><span>
</span><span id="line-30"></span><span id="wordToFloat"><span class="annot"><span class="annottext">wordToFloat :: Word32 -&gt; Float
</span><a href="Data.Binary.FloatCast.html#wordToFloat"><span class="hs-identifier hs-var hs-var">wordToFloat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Float
</span><a href="../../base/src/GHC.Float.html#castWord32ToFloat"><span class="hs-identifier hs-var">castWord32ToFloat</span></a></span><span>
</span><span id="line-31"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.Binary.FloatCast.html#wordToFloat"><span class="hs-pragma hs-type">wordToFloat</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-32"></span><span>
</span><span id="line-33"></span><span class="annot"><a href="Data.Binary.FloatCast.html#doubleToWord"><span class="hs-identifier hs-type">doubleToWord</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Double</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span>
</span><span id="line-34"></span><span id="doubleToWord"><span class="annot"><span class="annottext">doubleToWord :: Double -&gt; Word64
</span><a href="Data.Binary.FloatCast.html#doubleToWord"><span class="hs-identifier hs-var hs-var">doubleToWord</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Double -&gt; Word64
</span><a href="../../base/src/GHC.Float.html#castDoubleToWord64"><span class="hs-identifier hs-var">castDoubleToWord64</span></a></span><span>
</span><span id="line-35"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.Binary.FloatCast.html#doubleToWord"><span class="hs-pragma hs-type">doubleToWord</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span class="annot"><a href="Data.Binary.FloatCast.html#wordToDouble"><span class="hs-identifier hs-type">wordToDouble</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Double</span></span><span>
</span><span id="line-38"></span><span id="wordToDouble"><span class="annot"><span class="annottext">wordToDouble :: Word64 -&gt; Double
</span><a href="Data.Binary.FloatCast.html#wordToDouble"><span class="hs-identifier hs-var hs-var">wordToDouble</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word64 -&gt; Double
</span><a href="../../base/src/GHC.Float.html#castWord64ToDouble"><span class="hs-identifier hs-var">castWord64ToDouble</span></a></span><span>
</span><span id="line-39"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.Binary.FloatCast.html#wordToDouble"><span class="hs-pragma hs-type">wordToDouble</span></a></span><span> </span><span class="hs-pragma">#-}</span><span class="hs-cpp">

#else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Word</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Word32</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Word64</span><span class="hs-special">)</span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Array.ST</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">newArray</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">readArray</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MArray</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">STUArray</span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Array.Unsafe</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">castSTUArray</span><span class="hs-special">)</span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.ST</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">runST</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ST</span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span class="hs-identifier">floatToWord</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Float</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Word32</span><span>
</span><span id="line-48"></span><span class="hs-identifier">floatToWord</span><span> </span><span class="hs-identifier">x</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">runST</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">cast</span><span> </span><span class="hs-identifier">x</span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">floatToWord</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-50"></span><span>
</span><span id="line-51"></span><span class="hs-identifier">wordToFloat</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Word32</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Float</span><span>
</span><span id="line-52"></span><span class="hs-identifier">wordToFloat</span><span> </span><span class="hs-identifier">x</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">runST</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">cast</span><span> </span><span class="hs-identifier">x</span><span class="hs-special">)</span><span>
</span><span id="line-53"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">wordToFloat</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-54"></span><span>
</span><span id="line-55"></span><span class="hs-identifier">doubleToWord</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Double</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Word64</span><span>
</span><span id="line-56"></span><span class="hs-identifier">doubleToWord</span><span> </span><span class="hs-identifier">x</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">runST</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">cast</span><span> </span><span class="hs-identifier">x</span><span class="hs-special">)</span><span>
</span><span id="line-57"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">doubleToWord</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="hs-identifier">wordToDouble</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Word64</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Double</span><span>
</span><span id="line-60"></span><span class="hs-identifier">wordToDouble</span><span> </span><span class="hs-identifier">x</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">runST</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">cast</span><span> </span><span class="hs-identifier">x</span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">wordToDouble</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span class="hs-identifier">cast</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">MArray</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">STUArray</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ST</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-64"></span><span>         </span><span class="hs-identifier">MArray</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">STUArray</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">b</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ST</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">ST</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-identifier">b</span><span>
</span><span id="line-65"></span><span class="hs-identifier">cast</span><span> </span><span class="hs-identifier">x</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">newArray</span><span> </span><span class="hs-special">(</span><span class="hs-number">0</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Int</span><span class="hs-special">,</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">x</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">castSTUArray</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">flip</span><span> </span><span class="hs-identifier">readArray</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-66"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">cast</span><span> </span><span class="hs-pragma">#-}</span><span class="hs-cpp">
#endif
</span></pre></body></html>